package cn.com.lc.UseAnnotation;

import java.lang.reflect.Method;

@Pro(className = "cn.com.lc.UseAnnotation.Demo1",methodName = "show")
public class ReflectTest  {
    public static void main(String[] args) throws Exception{
        //1.解析注解，获取该类的字节码文件对象
        Class<ReflectTest> reflectTestClass = ReflectTest.class;
        //获取上面的注解对象
        //其实就是在内存中生成一个该注解接口的子类实现对象
        Pro annotation = reflectTestClass.getAnnotation(Pro.class);
        //调用注解对象中定义的抽象类方法，获取返回值
        String s = annotation.className();
        String s1 = annotation.methodName();
        System.out.println(s);
        System.out.println(s1);




        //加载进内存
        Class<?> aClass = Class.forName(s);
        //生成对象
        Object o = aClass.newInstance();
        //输出类名
        System.out.println(o.getClass());
        //获取方法
        Method method = aClass.getMethod(s1);
        System.out.println(method.getName());
        method.invoke(o);

    }
}
